﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.ComponentModel;

    [ScriptType("SP.SecurableObject", ServerTypeId="{1b1bf348-994e-44fd-823f-0748f5ad94c8}")]
    public class SecurableObject : ClientObject
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public SecurableObject(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        [Remote]
        public virtual void BreakRoleInheritance(bool copyRoleAssignments, bool clearSubscopes)
        {
            ClientAction query = new ClientActionInvokeMethod(this, "BreakRoleInheritance", new object[] { copyRoleAssignments, clearSubscopes });
            base.Context.AddQuery(query);
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (!flag)
            {
                string str = peekedName;
                if (str == null)
                {
                    return flag;
                }
                if (!(str == "RoleAssignments"))
                {
                    if (str == "HasUniqueRoleAssignments")
                    {
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["HasUniqueRoleAssignments"] = reader.ReadBoolean();
                    }
                    return flag;
                }
                flag = true;
                reader.ReadName();
                this.RoleAssignments.FromJson(reader);
            }
            return flag;
        }

        [Remote]
        public virtual void ResetRoleInheritance()
        {
            ClientAction query = new ClientActionInvokeMethod(this, "ResetRoleInheritance", null);
            base.Context.AddQuery(query);
        }

        [Remote]
        public bool HasUniqueRoleAssignments
        {
            get
            {
                base.CheckUninitializedProperty("HasUniqueRoleAssignments");
                return (bool) base.ObjectData.Properties["HasUniqueRoleAssignments"];
            }
        }

        [Remote]
        public RoleAssignmentCollection RoleAssignments
        {
            get
            {
                object obj2;
                if (base.ObjectData.ClientObjectProperties.TryGetValue("RoleAssignments", out obj2))
                {
                    return (RoleAssignmentCollection) obj2;
                }
                RoleAssignmentCollection assignments = new RoleAssignmentCollection(base.Context, new ObjectPathProperty(base.Context, base.Path, "RoleAssignments"));
                base.ObjectData.ClientObjectProperties["RoleAssignments"] = assignments;
                return assignments;
            }
        }
    }
}

